<template>
	<view class="all">
		<view style="width: 100%; height: auto; overflow: hidden;">
			<image class="box" mode="widthFix" src="../../static/image/banner.jpg"></image>
		</view>
		<view v-if="news.length>0">
			<view class="tab" v-for="(item,i) in news" :key="i">
				<view class="td"  @click="todetail(item.id)">
					<view class="message">
						<view class="time">{{createTime[i]}}</view>
					</view>
					<view class="name">{{item.name.length>15 ? item.name.substring(0,15)+'...' : item.name}}</view>
					<view class="message1" >
						<view class="detail">查看详情</view>
					</view>
				</view>
			</view>
		</view>
		<view v-else class="td1">暂无资讯信息，请稍后再来！！！</view>
	</view>
</template>

<script>
	import {
		getFindByAllNews
	} from "@api"
	import Vue from "vue"
	export default {
		"name" : "newsList",
		data() {
			return {
				news: [],
				size: 10,
				page: 0,
				createTime: [],
				updateTime: [],
				type: 0,
				assId:'',
			}
		},
		onLoad(e) {
			this.type = e.type;
			this.assId = e.assId;
			this.getNewsList();
		},
		methods: {
			//获取资讯列表
			getNewsList:function(){
				var that = this;
				if(that.type ==1){
					that.assId = 'null';
				}else if(that.type == 2){
					that.assId = that.assId;
				}
				getFindByAllNews({
						page: that.page,
						size: that.size,
						assId: that.assId
					})
					.then(res => {
						that.news = res;
						for (var i = 0; i < res.length; i++) {
							//创建时间转换(将时间戳转换成yyyy-MM-dd hh:mm:ss)
							that.createTime[i] = that.happenTimeFun(res[i].create_time);
							//修改时间转换(将时间戳转换成yyyy-MM-dd hh:mm:ss)
							that.updateTime[i] = that.happenTimeFun(res[i].update_time);
						}
					})
				
			},
			getMoreNews: function() { //数据到底,触发这个函数
				this.page = this.page + 1
				uni.showNavigationBarLoading(); //一读取数据,就进行刷新
				getFindByAllNews({
						page: this.page,
						size: this.size,
						assId: that.assId
					})
					.then(res => {
						if (res == 0) {
							this.page = this.page - 1
							uni.stopPullDownRefresh(); //数据加载完成,刷新结束
							uni.hideNavigationBarLoading(); //数据读取完毕,刷新停止
							return false;
						}
						this.news = this.news.concat(Array.from(res))
						for (var i = 0; i < res.length; i++) {
							//创建时间转换(将时间戳转换成yyyy-MM-dd hh:mm:ss)
							this.createTime[i] = this.happenTimeFun(res[i].create_time);
							//修改时间转换(将时间戳转换成yyyy-MM-dd hh:mm:ss)
							this.updateTime[i] = this.happenTimeFun(res[i].update_time);
						}
						uni.stopPullDownRefresh(); //数据加载完成,刷新结束
						uni.hideNavigationBarLoading(); //数据读取完毕,刷新停止
					})
			},
			happenTimeFun(num) { //时间戳数据处理
				let date = new Date(parseInt(num));
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h; //小时补0
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m; //分钟补0
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s; //秒补0
				return y + '-' + MM + '-' + d; //年月日时分秒
			},
			//跳转到咨询详情页面
			todetail(id) {
				this.$Router.push({
					name: 'information',
					params: {
						id
					}
				})
			}
		}
	}
</script>

<style>
	.box {
		width: 100%;
		height: 300rpx;
		background-repeat: no-repeat;
		background-position: 0 0;
		background-size: cover;
	}
	
	.message {
		display: flex;
		margin-top: 10rpx;
	}

	.time {
		font-size: 25rpx;
		padding-left: 580rpx;
		padding-top: 12rpx;
		color: #808080;
	}

	.message1 {
		display: flex;
		border-top: solid 0.5rpx #F9F9F9;
	}

	.detail {
		font-size: 30rpx;
		font-weight: 400;
		padding-top: 20rpx;
		padding-left: 40rpx;
		padding-bottom: 10rpx;
	}

	.name {
		font-size: 35rpx;
		font-weight: 600;
		margin-left: 42rpx;
		margin-top: 30rpx;
	}

	.name1 {
		font-size: 30rpx;
		margin-left: 44rpx;
		margin-top: 30rpx;
		margin-bottom: 15rpx;
		color: #808080;
	}

	.tit {
		color: #007AFF;
		margin: 10rpx 10rpx;

	}
	.tab {
		/* margin-top: 20rpx; */
		border-bottom: 2rpx solid #be2b24;
	}

	.all {
		background-color: #F1F1F1;
	}

	.td {
		width: 100%;
		background-color: #FFFFFF;
	}

	.td1 {
		width: 100%;
		background-color: #FFFFFF;
		/* margin-top: 20rpx; */
		text-align: center;
	}

	.te1 {
		font-size: 28rpx;

		margin: 20rpx 20rpx;
		margin-left: 590rpx;
		color: #007AFF;
	}
</style>
